function phi = fixedsolve(AB, AL, AC, AR, AT, sct, S, N, M, numg)
% function phi = fixedsolve(AB, AL, AC, AR, AT, sct, S, N, M, numg)
%   This function solves the fixed source, multi-group
%   diffusion equation given the appropriate coef diagonals,
%   scattering matrix, and source

%   NOTE: for larger problems, it may be worth exploring
%         iterative methods for solution

phi = zeros( (N+1)*(M+1), numg );
scsrc = zeros( (N+1)*(M+1), 1);
% solve the first group flux
A = spdiags([AB(:,1) AL(:,1) AC(:,1) AR(:,1) AT(:,1)], ...
    [-N-1 -1 0 1 N+1],(N+1)*(M+1),(N+1)*(M+1));
phi(:,1) = A \ S(:,1) ;
for g = 2:numg
    scsrc   = zeros( (N+1)*(M+1), 1);
    % compute scattering source
    for gg = 1:g-1 
        scsrc(:,1) = scsrc(:,1) + sct(:,g,gg).*phi(:,gg);
    end
    % solve for phi_g
    A = spdiags([AB(:,g) AL(:,g) AC(:,g) AR(:,g) AT(:,g)], ...
        [-N-1 -1 0 1 N+1],(N+1)*(M+1),(N+1)*(M+1));
    phi(:,g) = A \ ( S(:,g) + scsrc(:,1) );
end % ------------------------------------------------------------------